<?php
namespace app\index\controller;

use think\captcha\Captcha;
use think\Controller;
use think\facade\Request;

class Dynamic extends MyController
{
    public function index()
    {
        //会员动态
        $current = input('page',1);
        $limit = 5;
        $start = ($current - 1)* $limit;
        $dynamic = db('dynamic')
            ->alias('d')
            ->field('dy_id,content,media,pubtime,u.username,u.face')
            ->leftJoin('user u','d.u_id=u.u_id')
            ->order('dy_id','DESC')
            ->limit($start,$limit)
            ->paginate($limit);

        //推荐好文
        $recommend = db('information')
            ->where('recommend',1)
            ->order('info_id','DESC')
            ->limit(6)
            ->select();
        $this->assign([
            'dynamic'=>$dynamic,
            'recommend' => $recommend,
        ]);
        return view();
    }

    /**
     * 点赞会员动态
     */
    public function praise(){
        if (Request::isAjax())
        {
            $did = Request::get('id');
            if(db('dynamic')->where('dy_id',$did)->setInc('praise')){
                echo 1;exit;
            }else{
                echo 0;exit;
            }
        }
    }
}
